package com.ruoyi.project.infoprojectcapitalannex.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.infoprojectcapitalannex.domain.InfoProjectCapitalAnnex;
import com.ruoyi.project.infoprojectcapitalannex.service.IInfoProjectCapitalAnnexService;
import com.ruoyi.project.infoprojectcapitalannex.vo.InfoProjectCapitalAnnexVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目资金附件Controller
 *
 * @author ruoyi
 * @date 2022-02-09
 */
@RestController
@RequestMapping("/infoProjectCapitalAnnex/infoProjectCapitalAnnex")
public class InfoProjectCapitalAnnexController extends BaseController {
    @Autowired
    private IInfoProjectCapitalAnnexService infoProjectCapitalAnnexService;

    /**
     * 查询项目资金附件列表
     */
//    @PreAuthorize("@ss.hasPermi('infoProjectCapitalAnnex:infoProjectCapitalAnnex:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoProjectCapitalAnnex infoProjectCapitalAnnex) {
        startPage();
        List<InfoProjectCapitalAnnex> list = infoProjectCapitalAnnexService.selectInfoProjectCapitalAnnexList(infoProjectCapitalAnnex);
        return getDataTable(list);
    }

    /**
     * 导出项目资金附件列表
     */
    @PreAuthorize("@ss.hasPermi('infoProjectCapitalAnnex:infoProjectCapitalAnnex:export')")
    @Log(title = "项目资金附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoProjectCapitalAnnex infoProjectCapitalAnnex) {
        List<InfoProjectCapitalAnnex> list = infoProjectCapitalAnnexService.selectInfoProjectCapitalAnnexList(infoProjectCapitalAnnex);
        ExcelUtil<InfoProjectCapitalAnnex> util = new ExcelUtil<InfoProjectCapitalAnnex>(InfoProjectCapitalAnnex.class);
        util.exportExcel(response, list, "项目资金附件数据");
    }

    /**
     * 获取项目资金附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('infoProjectCapitalAnnex:infoProjectCapitalAnnex:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(infoProjectCapitalAnnexService.selectInfoProjectCapitalAnnexById(id));
    }

    /**
     * 新增项目资金附件
     */
    @PreAuthorize("@ss.hasPermi('infoProjectCapitalAnnex:infoProjectCapitalAnnex:add')")
    @Log(title = "项目资金附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoProjectCapitalAnnex infoProjectCapitalAnnex) {
        return toAjax(infoProjectCapitalAnnexService.insertInfoProjectCapitalAnnex(infoProjectCapitalAnnex));
    }

    /**
     * 修改项目资金附件
     */
    @PreAuthorize("@ss.hasPermi('infoProjectCapitalAnnex:infoProjectCapitalAnnex:edit')")
    @Log(title = "项目资金附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoProjectCapitalAnnex infoProjectCapitalAnnex) {
        return toAjax(infoProjectCapitalAnnexService.updateInfoProjectCapitalAnnex(infoProjectCapitalAnnex));
    }

    /**
     * 删除项目资金附件
     */
//    @PreAuthorize("@ss.hasPermi('infoProjectCapitalAnnex:infoProjectCapitalAnnex:remove')")
    @Log(title = "项目资金附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(infoProjectCapitalAnnexService.deleteInfoProjectCapitalAnnexByIds(ids));
    }


    /**
     * 批量增加项目附件
     *
     * @param infoProjectCapitalAnnexVo
     * @return
     */
    @RequestMapping(value = "/batchInsert", method = RequestMethod.POST)
    public AjaxResult batchInsert(@RequestBody InfoProjectCapitalAnnexVo infoProjectCapitalAnnexVo) {
        return toAjax(infoProjectCapitalAnnexService.batchInsert(infoProjectCapitalAnnexVo));
    }
}
